package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Autowired
    private DishService dishService;
    @PostMapping
    @ApiOperation("新增菜品")
    public Result add(@RequestBody DishDTO dto){
        log.info("新增菜品{}",dto);
        dishService.add(dto);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("菜品分页条件查询")
    public Result<PageResult> page(DishPageQueryDTO dto){
        log.info("菜品分页条件查询{}",dto);
        PageResult p= dishService.page(dto);
        return Result.success(p);
    }
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result delete(@RequestParam List<Integer>ids){
        log.info("批量删除菜品{}",ids);
        dishService.delete(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("查询回显")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询回显{}",id);
        DishVO d= dishService.getInfo(id);
        return Result.success(d);
    }
    @GetMapping("/list")
    @ApiOperation("分类id查菜品")
    public Result<List<Dish>> getBycId( Integer categoryId){
        log.info("分类id查菜品{}",categoryId);
        List<Dish> d= dishService.getBycId(categoryId);
        return Result.success(d);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishDTO dto){
        log.info("修改菜品");
        dishService.update(dto);
        return Result.success();
    }
}
